package com.kira.scaffoldmvc.Utils;

import com.kira.scaffoldmvc.POJO.Annotation.Check;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import lombok.extern.slf4j.Slf4j;


@Slf4j
public class CheckAccountValidation implements ConstraintValidator<Check, String> {


    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {

        //账号只能是数字
        for (char c : value.toCharArray()) {
            if (!Character.isDigit(c)) {
                return false;
            }
        }
        //限制账号的长度
        if (value == null || value.length() < 6 || value.length() > 10) {
            return false;
        }
        //账号的首位数不能为0
        if (value.charAt(0) == '0') {
            return false;
        }
        log.info(value);
        return true;


    }
}
